package nina.yiyou.performance.s11collect.compute

import nina.yiyou.performance.s11collect.input.CollectFilledReader

import java.util.stream.Collectors

class EvalCommentCollector {

  interface Comment {

    String targetName()

    String fillerName()

    String content()
  }

  EvalCommentCollector(List<CollectFilledReader.Filler> fillerList) {
    _fillerList = fillerList
  }

  List<Comment> collectList() {
    def toComment = { CollectFilledReader.Eval e ->
      return new Comment() {
        @Override
        String targetName() {
          return e.evaluateeName() + '_' + e.evaluateeId()
        }

        @Override
        String fillerName() {
          return e.fillerName() + '_' + e.fillerId()
        }

        @Override
        String content() {
          return e.value()
        }
      }
    }

    return _fillerList.stream()
        .flatMap { it.otherEval().values().stream() }
        .map { it[-1] }
        .map { CollectFilledReader.Eval e -> toComment.call(e) }
        .sorted(Comparator.comparing { Comment c -> c.targetName() })
        .collect(Collectors.toList())
  }

  private final List<CollectFilledReader.Filler> _fillerList
}
